package com.zang.greedy;

/**
 * @author ZVerify
 * @since 2022/11/22 19:07
 * @see <a href="https://leetcode.cn/problems/lemonade-change/">...</a>
 **/
public class 柠檬水找零 {
    // 不管你给我多少直接找你钱，我只要欠了钱就返回false
    public boolean lemonadeChange(int[] bills) {

        int five = 0;
        int ten = 0;

        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) {
                five++;
            }else if (bills[i] ==10) {
                ten++;
                five--;
            }else if (bills[i] == 20) {
                if (ten > 0) {
                    ten--;
                    five--;
                }else {
                    five = five-3;
                }
            }
            // 欠费了直接返回false
            if (five < 0 ) return false;
        }
        // 顾客都走了还没有欠费返回true
        return true;
    }
}
